      SUBROUTINE ORTHO(LI,LC,B,KG)
c
c23456789012345678901234567890123456789012345678901234567890123456789012
c
C    FINDS THE ORTHOGONAL MATRIX V SUCH THAT THE COLUMNS OF B*V ARE ORTHOGONAL
C   THE ARRAY A IS REPLACED BY A*V FOR LEVELS LI - LC. ARRAY B IS REPLACED
C   BY B*V AND IS THEN READY FO ENTRY TO SPROP AT LEVEL LC.THIS IS INTENDED
C   TO DIMINISH THE ONSET OF DEGENERACY CAUSED BY RAPID EXPONENTIAL GROWTH
C    IN THE MANTLE FOR MODES WITH DEEPLY TURNING S AND SHALLOWLY TURNING P.
c
c    calls: SVD
c
      IMPLICIT REAL*8(A-H,O-Z)
c
      SAVE
c
      include 'parameter.h'
c
      COMMON/AREM/A(6,3,nknot)
      DIMENSION B(6,1),AS(6,3)
      DATA AS/18*0.D0/
c
      I1=MIN0(LC,LI)
      I2=MAX0(LC,LI)
      NC=KG+2
      NR=2*NC
c
      CALL SVD(B,NR,NC)
c
      DO 25 I=I1,I2
      DO 20 J=1,NC
      DO 20 K=1,NR
      AS(K,J)=0.D0
      DO 20 L=1,NC
   20 AS(K,J)=AS(K,J)+A(K,L,I)*B(L,J)
      DO 25 J=1,NC
      DO 25 K=1,NR
   25 A(K,J,I)=AS(K,J)
      DO 35 J=1,NC
      DO 35 K=1,NR
   35 B(K,J)=A(K,J,LC)
c
      RETURN
      END
